<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

// need to evolve search
if( $_GET["date_start"] AND $_GET["date_end"] )
{
	$date_start = strip_tags($_GET["date_start"]);	
	$date_end = strip_tags($_GET["date_end"]);
	
	file_put_contents  ( "params_search_date.txt", 
								"date_start '" .$date_start.
								"' date_end '" .$date_end."'");
	/*
	$query = new Doctrine_Query();
   	$query->from('FinTransactions')
				->where('deleted = 0 
						 AND t_date BETWEEN ($year_start, $year_end)
            	->orderby('year_start');
                  
   	$items = $query->execute();	   
   	file_put_contents  ( "select_by_centre.txt", $items);
	*/
}
else if ($_GET["currency_id"]) 
{
	$currency_id = strip_tags($_GET["currency_id"]);	
	file_put_contents  ( "param_search_str.txt", $currency_id);
	
	$query = new Doctrine_Query();
   	$query->from('FinExchangeRates')
				->where('deleted = 0 
							AND currency_id ='.$currency_id);
                  
   	$items = $query->execute();
   	file_put_contents  ( "select_by_centre.txt", $items);
}
else if ($_GET["source_id"]) 
{	
	$source_id = strip_tags($_GET["source_id"]);
	$query = new Doctrine_Query();
    $query->from('FinExchangeRates')
				->where('deleted = 0 
							AND source_id ='.$source_id);
                  
    $items = $query->execute();	
    file_put_contents  ( "select_all.txt", $items);
}
            
/// Return XML
$str.='<results>';
	foreach ($items as $item){
		$str.='<record>';
			$str.='<currency_id>'.$item["currency_id"].'</currency_id>';
			$str.='<date_start>'.$item["date_start"].'</date_start>';
			$str.='<date_end'.$item["date_end"].'</date_end>';
			$str.='<exchange_rate>'.$item["exchange_rate"].'</exchange_rate>';
			$str.='<created>'.$item["created"].'</created>';
		$str.='</record>';
	}
$str.='</results>';
   
header ("content-type: text/xml"); 
echo $str;

file_put_contents  ( "getExRateOut.txt", $str);

?>